package com.pipayshop.controller;

import com.pipayshop.domain.StoreCategoryMin;
import com.pipayshop.domain.dto.StoreInfoMinListByConditionDTO;
import com.pipayshop.domain.vo.PageDataVO;
import com.pipayshop.service.PhysicalStoreCategoryMinService;
import com.pipayshop.entity.vo.ResponseVO;
import com.pipayshop.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 实体店三级分类表 前端控制器
 * @author wzx
 */
@Api(value = "实体店三级分类",tags = "实体店三级分类")
@RestController
@RequestMapping("/pipayshopapi/store-category-min")
@Slf4j
public class PhysicalStoreCategoryMinController {

    @Resource
    PhysicalStoreCategoryMinService shopCategoryMinService;


    @GetMapping("getShopCategoryMinList/{categoryPid}")
    @ApiOperation("实体店三级分类标签列表展示")
    public ResponseVO<List<StoreCategoryMin>> getShopCategoryMinList(@PathVariable String categoryPid) {
        try {
            List<StoreCategoryMin> list = shopCategoryMinService.getShopCategoryMinList(categoryPid);
            return ResponseVO.getSuccessResponseVo(list);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new BusinessException("get_third_level_category_list_failed");
        }
    }

    @GetMapping("getShopInfoMinListByCondition")
    @ApiOperation("二级分类标签列表对应的店铺列表条件分页展示")
    public ResponseVO<PageDataVO> getShopInfoMinListByCondition(StoreInfoMinListByConditionDTO shopInfoMinListByConditionDTO){
        try {
            PageDataVO shopInfoMinListByCondition = shopCategoryMinService.getShopInfoMinListByCondition(shopInfoMinListByConditionDTO);
            if (shopInfoMinListByCondition==null){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo(shopInfoMinListByCondition);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("条件筛选失败");
        }
    }
}
